﻿#include "GameStart.h"
#include"GameButton.h"
#include"Game.h"
GameStart::GameStart(const int x, const int y, QWidget* parent)
{
	setType(Entity::Type::gameStart);
	this->m_parent = parent;
	move(x, y);
	init();
	m_OnPlayerLevel = new GameButton("菜单按钮",parent);
	m_OnPlayerLevel->move(90, 480);
	m_OnPlayerLevel->setText("单人关卡");
	m_OnPlayerLevel->show();
	QObject::connect(m_OnPlayerLevel, &QPushButton::clicked,(Game*)parent,&Game::CreateOnPlayerLevel);

	m_NetworkModel = new GameButton("菜单按钮",parent);
	m_NetworkModel->move(90, 580);
	m_NetworkModel->setText("网络模式");
	m_NetworkModel->show();
	QObject::connect(m_NetworkModel, &QPushButton::clicked, (Game*)parent, &Game::CreateNetworkModel);
	
	 m_Quit = new GameButton("菜单按钮",parent);
	m_Quit->move(90, 680);
	m_Quit->setText("退出游戏");
	m_Quit->show();
	QObject::connect(m_Quit, &QPushButton::clicked, [=]() {parent->close(); });
}

void GameStart::init()
{
	addFrame("背景图片", "正常");
	addFrame("标题", "标题");
}

void GameStart::update()
{
	Background::update();
}

void GameStart::draw(QPainter* painter)
{
	Background::draw(painter);
	getModel()["标题"].draw(painter, QPoint(20,300));
}

GameStart::~GameStart()
{
	if(m_OnPlayerLevel!=nullptr)
		delete m_OnPlayerLevel;
	if (m_NetworkModel != nullptr)
		delete m_NetworkModel;
	if (m_Quit != nullptr)
		delete m_Quit;
	//qDebug() << "释放按钮";
}
